package leetcode41_50;

import org.junit.Test;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;

/**
 * @author shhjiang_001
 * @create 2020-06-17 22:03
 */

        /*
        给定一个 没有重复 数字的序列，返回其所有可能的全排列。
        示例:
        输入: [1,2,3]
        输出:
        [
        [1,2,3],
        [1,3,2],
        [2,1,3],
        [2,3,1],
        [3,1,2],
        [3,2,1]
        ]
        */


public class Solution46 {
    List<List<Integer>> list = new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        int pos = 0;
        ArrayDeque<Integer> deque = new ArrayDeque<>();
        method(nums,pos,deque);
        return list;
    }

    private void method(int[] nums, int pos, ArrayDeque<Integer> list1) {
        if (pos > nums.length-1){
            list.add(new ArrayList<>(list1));
            return;
        }
        for (int i = 0;i<nums.length;i++){
            if (i > 0 ){

            }
            if (!list1.contains(nums[i])){
                list1.add(nums[i]);
                method(nums,pos+1,list1);
                list1.removeLast();
            }

        }
    }
    @Test
    public void test() {
        Solution46 solution46 = new Solution46();
//        System.out.println(Arrays.asList(new int[]{1, 2, 3}).toString());
        solution46.permute(new int[]{1,2,3});
    }
}
